<template>
  <div class="bankAdd">
    <div>
      <el-button type="primary" size="mini" @click="save">{{ $t('btn.save') }}</el-button>
    </div>
    <el-form :model="proValue" size="mini" label-width="100px">
      <!--      <el-form-item label="创建组织">-->
      <!--        <el-select v-model.trim="proValue.fcreateorgId">-->
      <!--          <el-option-->
      <!--            v-for="option in teamList"-->
      <!--            :key="option.fid"-->
      <!--            :label="option.fname"-->
      <!--            :value="option.fid"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="使用组织">-->
      <!--        <el-select v-model.trim="proValue.fuseorgId">-->
      <!--          <el-option-->
      <!--            v-for="option in teamList"-->
      <!--            :key="option.fid"-->
      <!--            :label="option.fname"-->
      <!--            :value="option.fid"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item :label="$t('market.accountname1')">
        <el-input v-model="proValue.faccountname" />
      </el-form-item>
      <el-form-item :label="$t('market.bankcode')">
        <el-input v-model="proValue.faccount" />
      </el-form-item>
      <el-form-item :label="$t('market.bankDeposit')">
        <el-select v-model.trim="proValue.faccountbanknameId" filterable>
          <el-option
            v-for="option in account1"
            :key="option.fid"
            :label="option.fname"
            :value="option.fid"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('market.accountattribute')">
        <el-select v-model.trim="proValue.faccountattributeId" filterable>
          <el-option
            v-for="option in account2"
            :key="option.fid"
            :label="option.fname"
            :value="option.fid"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('market.accounttype')">
        <el-select v-model.trim="proValue.faccounttypeId" filterable>
          <el-option
            v-for="option in account3"
            :key="option.fid"
            :label="option.fname"
            :value="option.fid"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('market.currency2')">
        <el-input v-model.trim="proValue.fcurrencyname">
          <i
            slot="suffix"
            class="el-input__icon el-icon-search"
            @click="currencyVisiblit=true"
          />
        </el-input>
      </el-form-item>
      <el-form-item :label="$t('market.upstockmode')">
        <el-select v-model.trim="proValue.fupstockmodeId" filterable>
          <el-option
            v-for="option in account4"
            :key="option.fid"
            :label="option.fname"
            :value="option.fid"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('market.upstocknum')">
        <el-input-number v-model="proValue.fupstocknum" controls-position="right" />
      </el-form-item>
      <el-form-item :label="$t('market.retainedbalance')">
        <el-input-number v-model="proValue.fretainedbalance" controls-position="right" />
      </el-form-item>
      <el-form-item :label="$t('market.minimumupstocknum')">
        <el-input-number v-model="proValue.fminimumupstocknum" controls-position="right" />
      </el-form-item>
      <el-form-item :label="$t('market.note')">
        <el-input v-model="proValue.fremark" />
      </el-form-item>
    </el-form>
    <!--币别-->
    <currency v-if="currencyVisiblit" @currency="currencyData" />
  </div>
</template>

<script>
import bility from '@/mixin/Operability'
import { queryViewItem } from '@/api/marketManage/marketOrder'
import { insertBankAccount } from '@/api/financial/teller'
import autocomplete from '@/views/market/marketManage/createMarkerOrder/components/autocomplete'

export default {
  components: {
    currency: () => import('@/views/market/marketManage/createMarkerOrder/components/currency')
  },
  mixins: [autocomplete, bility],
  data() {
    return {
      currencyVisiblit: false,
      proValue: {
        fcreateorgId: 1,
        fuseorgId: 1,
        faccount: '',
        faccountname: '',
        faccountbanknameId: '',
        faccountattributeId: '',
        faccounttypeId: '',
        fcurrencyId: '',
        fupstockmodeId: '',
        fupstocknum: '',
        fretainedbalance: '',
        fminimumupstocknum: '',
        fremark: ''
      },
      account1: [], // 开户行
      account2: [], // 账户收支属xing
      account3: [], // 账号类型
      account4: [] // 上划方式
    }
  },
  created() {
    this.getForm()
    this.getForm2()
    this.getForm3()
    this.getForm4()
  },
  methods: {
    // 保存
    save() {
      insertBankAccount(this.proValue).then(res => {
        if (res.code === 0) {
          // 关闭当前页面
          this.$store.dispatch('tagsView/guanbi', this.$route)
          this.$router.push({ path: `/bankDetail/${res.data.fbankaccountId}` })
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 开户银行数据
    async getForm() {
      await queryViewItem({ viewName: 'SX_FIN_BANK' }).then(res => {
        this.account1 = res.data.list
      })
    },
    // 账户收支属xing
    async getForm2() {
      await queryViewItem({ viewName: 'SX_V_ARAE' }).then(res => {
        this.account2 = res.data.list
      })
    },
    // 账号类型
    async getForm3() {
      await queryViewItem({ viewName: 'SX_FIN_ACCOUNTTYPE' }).then(res => {
        this.account3 = res.data.list
      })
    },
    // 上划方式
    async getForm4() {
      await queryViewItem({ viewName: 'SX_FIN_UPMODE' }).then(res => {
        this.account4 = res.data.list
      })
    },
    // 币别
    currencyData(item) {
      if (item.fsettleCurrId || item.fcurrencyId) {
        this.proValue.fcurrencyname = item.fsettleCurrIdName || item.fname
        this.proValue.fcurrencyId = item.fsettleCurrId || item.fcurrencyId
      }
      this.currencyVisiblit = false
    }
  }
}
</script>

<style scoped lang="scss">
.bankAdd {
  @include listBom;
  background: #fff;
  .el-input::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }
  .el-form {
    margin-top: 5px;
    //display: flex;
    flex-wrap: wrap;
    .el-form-item {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-bottom: 10px;
      .el-input {
        width: 180px;
      }
    }
  }
}
</style>

